package com.caller.controller;

import com.common.compoent.PrintWriter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @Author Str
 * @Date 2022/1/5 10:35
 * @Description :
 */
@RestController
@RequestMapping("/userCall")
public class UserCallController {
    @Autowired
    private RestTemplate restTemplate;

    private String PREFIX = "http://localhost:8081";

    // localhost:8082/userCall/getStringData
    @RequestMapping("/getStringData")
    public String getStringData() {
        // 服务提供者的方法
        String url = PREFIX + "/user/getStringData";
        // url地址，返回值类型，参数
        String result = restTemplate.getForObject(url, String.class);
        PrintWriter.prtMark("caller.UserCallController.getStringData");
        return "来自其他服务的信息：" + result;
    }
}
